﻿-- =============================================
-- Script Template
-- =============================================
--建表
USE [uvp]
GO
/****** 对象:  Table [dbo].[ChartTimeRuler]    脚本日期: 05/20/2012 12:56:13 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ChartTimeRuler](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[RuleTime] [datetime] NOT NULL,
	[RealTime] [datetime] NULL,
 CONSTRAINT [PK_ChartTimeRuler] PRIMARY KEY CLUSTERED 
(
	[RuleTime] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
go

--导入初始数据==================================
	select * from dbo.ChartTimeRuler
	declare @i int ;set @i=0;
	declare @start datetime; set @start =  cast('2000-01-01 00:00:00' as datetime);
	declare  @dtm datetime ;set @dtm = getdate()
	set nocount on
	while @i<30000
		begin
			insert into dbo.ChartTimeRuler(RuleTime) values(dateadd(ss,@i*3,@start))
			set @i=@i+1
		end
	print(datediff(ms,@dtm,getdate())) --10820（导入性能较差）

--测试数据================================
	declare  @dtm datetime ;set @dtm = getdate()

	declare  @start datetime ;set @start = '2012-5-20 13:02:00'
	declare @distance datetime ;
	select @distance=@start-RuleTime from dbo.ChartTimeRuler where ID=1
	--执行更新
	update dbo.ChartTimeRuler set RealTime=RuleTime+@distance

	print(datediff(ms,@dtm,getdate())) --168ms（更新性能较好）
=========================================
